<?php use_javascript('jquery.timers-1.2.js')?>
<div id="answer_box">
    <?php if($show_result):?>
        <?php include_component('test', 'showresult', array('result_id' => $sf_user->getAttribute('result_id')))?>
    <?php else:?>
        <?php include_partial('testform', array('question' => $question, 'form' => $form, 'result_answer_prev' => $result_answer_prev, 'result_answer_next' => $result_answer_next))?>
    <?php endif;?>
</div>
<?php if(!$show_result && $time_to_and > 0):?>
    <div class="time_box">
        Часу до кінця тесту:&nbsp;<span id="timer"></span>
    </div>

    <script type="text/javascript">
        jQuery(document).ready(function() {
            $("#timer").everyTime(1000, function(i) {
              timer = <?php echo $time_to_and ?> - i;
              seconds = timer % 60;
              minutes = Math.round ( (timer - seconds) / 60);
              if( seconds < 10) seconds = '0'+seconds;
              $(this).text(minutes + ' : ' + seconds);
            });
        });
            $("#timer").oneTime("<?php echo $time_to_and ?>s", function() {
                data = jQuery.ajax({
                    url: "<?php echo url_for('@showresult')?>",
                    global: false,
                    dataType: "html",
                    success: function(data) {
                        jQuery("#answer_box").html(data);
                    }
                }).responseText;
            });
    </script>
<?php endif;?>